package yf.mall.service;

import com.yf.entity.TokenEntity;
import com.yf.entity.WxUser;
import org.apache.commons.collections4.MultiValuedMap;
import yf.mall.entity.TopRecordEntity;
import yf.mall.entity.UserEntity;
import com.yf.service.BaseService;
import yf.mall.vo.UserEntityVo;
import yf.mall.vo.UserVo;
import yf.mall.vo.app.UserUpdateDTO;
import yf.mall.vo.web.UserVO;
import yf.mall.vo.web.VipUserVO;

import javax.servlet.http.HttpServletResponse;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.function.Predicate;

/**
 * 用户Service接口
 *
 * 
 *
 * @date Thu Jul 11 12:00:51 CST 2019
 */
public interface UserService extends BaseService<UserEntity> {

    List<UserVo> queryListVo(UserVo userVo);

    UserVo getVo(Long id);

    UserEntity add(Long userId, String password);

    UserVo updateVo(UserVo userVo);


    UserEntity findByCode(String code);

    UserEntity findByMobile(String mobile);

    List<VipUserVO> findByVip(String tCode);

    void validateUser(UserEntity fromUser, UserEntity toUser);

    List<UserVo> findByNameOrCodeOrMobile(String param);

    //    List<UserEntity> findByTop(Long userId,Integer type);
    List<UserVo> findByTop(Long userId, Integer type);

    List<Long> findPidFromTeam(Long userId, String team);

    void changeRidFidByLevel(Long userId, Long oldLevelId, Long toLevelId);


    void validatePhone(String phone, UserEntity userEntity);

    //禁止状态用户不允许操作
    void validateUser(Long userId);

    /**
     * 找出级别比自己高的人
     *
     * @param userId
     * @return
     */
    UserEntity getLvTopUser(Long userId);

    /**
     * api
     */

    //手机号跟验证码登录
    TokenEntity phoneLogin(String code, String phone, String captcha, Boolean bindWx);

    //手机号登录 没有就注册
    TokenEntity phoneLogin(WxUser wxUser, String topCode, String phone, String captcha, Boolean isRegister);

    List<UserVO> findVOByWxId(String wxId);

    TokenEntity codeLogin(WxUser wxUser, String topCode, String code, String password, Boolean bindWx);

    void loginOut(Long userId, Integer type);

    //微信登录 是否直接注册
    TokenEntity wxLogin(WxUser wxUser, Long topUserId, Boolean register);

    TokenEntity wxLogin(WxUser wxUser, String topUserCode, Boolean register);

    TopRecordEntity changeTop(Long userId, Long topId, String info);

    //初始化团队
    List<String> initTeam(Long id);

    List<UserEntity> getTeamChildList(Long userId, Integer lv);

    //注册
    UserEntity register(String openId, String unionId, String name, String avatar, String phone, String captcha, Long topUserId, String remark);

    //扫描公众号注册
    UserEntity register(String openId, Long topUserId);

    //赠送名额注册
    UserEntity registerBySend(String phone, Long pid);

    //用户编辑  绑定手机号 同步账号
    UserEntity update(Long userId, String phone, String password, String name, Boolean sync, String topPhone);

    //通过微信OpenId或者UnionID查找
    UserEntity findByWxId(String wxId);

    UserEntity findByAny(String info);

//    UserEntityVo findNowUserInfo(Long userId);

    //找到领导人
    UserEntity findLeader(Long userId);

    //生成授权证书
    void createAuthImg(Long userId, HttpServletResponse response);

    //找出所有上级
    List<UserEntity> findAllTop(Long userId);


    //是否是红钻 下面三条线有三个真是蓝钻或者真是红钻
    List<UserEntity> isHVip(Long userId, MultiValuedMap source);

    //是否是蓝钻 下面三条线有三个是真实蓝钻或者粉钻
    List<UserEntity> isLVip(Long userId, MultiValuedMap source);

    //是否是粉钻
    Boolean isFVIp(Long userId);

    void eachTop(Long userId, Predicate<UserEntity> consumer);

    void eachChild(List<Long> topIds, Predicate<List<UserEntity>> consumer, Integer count);

    void eachChildByMap(List<Long> topIds, Map<Long, List<UserEntity>> source, Predicate<List<UserEntity>> consumer);

    void eachChildByMap(UserEntity topUser, Map source, Predicate<UserEntity> user);

    void eachVOChild(List<Long> topIds, Predicate<List<UserVO>> consumer);

    //更新用户的RID
    void initUserRidFid(UserEntity user);

    void initUserTeamCount(UserEntity user);

    List<UserEntity> findByPid(Long userId);

    UserEntity getLoginUser(String token);

    UserVO findVO(Long userId);


    List<UserVO> findVOByPid(Long userId, Integer type);

    UserVO findVOByAny(String name);

    List<UserEntity> findByMonth(Date date);


    List<UserEntity> finByUserIds(Set<Long> userIds);

    void down(List<UserVo> userList, HttpServletResponse response);


    void update(Long userId, UserUpdateDTO userUpdateDTO);

    UserEntity getChatUserInfo(Long userId);

    //2023-10-1以后的都是新人
    Boolean isNewDr(Long levelId,Date date);

    //是否可以招商 达人以及以上且不是新达人
    Boolean canShare(Long levelId,Date date);

    List<String> findAllOpenId();
}
